package com.schoolhelper.model.dao.jsonparse;

import com.alibaba.fastjson.JSONObject;
import com.schoolhelper.utils.constant.MessageConstant;

import lombok.SneakyThrows;

public class LwlControllerJsonParser extends EasyCodeJsonParser implements LwlJsonParser{

    @Override
    @SneakyThrows
    public String getSmmsUrl(String responseData) {
        JSONObject responseJson = (JSONObject) JSONObject.parse(responseData);

        switch (String.valueOf(responseJson.get("code"))) {
            case "success":
                JSONObject dataJson = (JSONObject) responseJson.get("data");
                return (String) dataJson.get("url");
            case "image_repeated":
                return (String) responseJson.get("images");
            default:
                return MessageConstant.FAIL_MSG;
        }
    }

    @Override
    public <T> T getOne(String responseData, Class<T> resultVoClass) {
        return JSONObject.parseObject(responseData, resultVoClass);
    }
}
